﻿#include <QApplication>
#include <QQmlApplicationEngine>
#include <cpp/log/logfile.h>
#include <QtQml>
#include "cpp/log/qmlobjecttest.h"
#include "cpp/log/qdebug2logcat.h"

#include <QDebug>
#include <QScreen>
#include <QFont>
#include <QtGui/QGuiApplication>
#include <QQuickView>

#include "cpp/mainwindow.h"
#include "cpp/upmainwindow.h"
#include "cpp/common/mycommon.h"

#ifdef ANDROID
#include <QAndroidJniEnvironment>
#include <QAndroidJniObject>
#endif


int main(int argc, char *argv[])
{

#ifdef ANDROID
    installLogcatMessageHandler("yourLogTag");
#else

    //打开日志文件，以文本写入方式
    logFile::g_log_fp = fopen("my.log", "wt");
    //程序退出时关闭日志文件
    atexit(logFile::closeLogFile);

    //使用我的日志类处理qt日志
    qInstallMessageHandler(logFile::myMessageOutput);

#endif

    QGuiApplication app(argc, argv);

    QScreen *screen = app.primaryScreen();
    QFont font = app.font();
    int pixelSize = (font.pointSize()*screen->logicalDotsPerInch()) / 72;

    Q_UNUSED(pixelSize);

    //    font.setPointSize(100);
    //    app.setFont(font);

    qmlRegisterType<qmlObjectTest>("QmlObjectTest", 1, 0, "QmlObjectTest");

    qmlRegisterType<MainWindow>("MainWindow", 1, 0, "MainWindow");
    qmlRegisterType<UpMainWindow>("UpMainWindow", 1, 0, "UpMainWindow");

#ifdef ANDROID
    qmlRegisterType<MyCommon>("MyCommon", 1, 0, "MyCommon");

#else
    qmlRegisterType<MyCommon>("MyCommon", 1, 0, "MyCommon");
#endif

    QQuickView view;

    view.setSource(QUrl("qrc:/main.qml"));
    view.setTitle(QStringLiteral("opengl and qml"));
    view.show();

    view.setVisibility(QWindow::Maximized);

    return app.exec();
}

